package com.ruoyi.cat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cat.domain.CatArea;
import com.ruoyi.cat.service.ICatAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区信息Controller
 * 
 * @author xin
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/cat/area")
public class CatAreaController extends BaseController
{
    @Autowired
    private ICatAreaService catAreaService;

    /**
     * 查询地区信息列表
     */
    @PreAuthorize("@ss.hasPermi('cat:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatArea catArea)
    {
        startPage();
        List<CatArea> list = catAreaService.selectCatAreaList(catArea);
        return getDataTable(list);
    }

    /**
     * 导出地区信息列表
     */
    @PreAuthorize("@ss.hasPermi('cat:area:export')")
    @Log(title = "地区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CatArea catArea)
    {
        List<CatArea> list = catAreaService.selectCatAreaList(catArea);
        ExcelUtil<CatArea> util = new ExcelUtil<CatArea>(CatArea.class);
        util.exportExcel(response, list, "地区信息数据");
    }

    /**
     * 获取地区信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('cat:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(catAreaService.selectCatAreaById(id));
    }

    /**
     * 新增地区信息
     */
    @PreAuthorize("@ss.hasPermi('cat:area:add')")
    @Log(title = "地区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatArea catArea)
    {
        return toAjax(catAreaService.insertCatArea(catArea));
    }

    /**
     * 修改地区信息
     */
    @PreAuthorize("@ss.hasPermi('cat:area:edit')")
    @Log(title = "地区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatArea catArea)
    {
        return toAjax(catAreaService.updateCatArea(catArea));
    }

    /**
     * 删除地区信息
     */
    @PreAuthorize("@ss.hasPermi('cat:area:remove')")
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(catAreaService.deleteCatAreaByIds(ids));
    }
}
